package nuonuo.com.view.customview;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import nuonuo.com.view.R;

/**
 * Created by n6 on 2017/3/6.
 */

public class MyAdapter extends BaseAdapter {
    private Context mContext;
    private OnHideItemClickListener mDel1;
    private OnHideItemClickListener mDel2;
    private OnHideItemClickListener mDel3;
    private OnItemClickListener mItemListener;
    public MyAdapter(Context context){
        mContext = context;
    }

    @Override
    public int getCount() {
        return 10;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item, parent, false);
        MyHorizantalScrollerView itemView = (MyHorizantalScrollerView) view.findViewById(R.id.hide_item);
        View delView1 = view.findViewById(R.id.del1);
        View delView2 = view.findViewById(R.id.del2);
        View delView3 = view.findViewById(R.id.del3);
        delView1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mDel1 != null){
                    mDel1.onHideItemClick(v,position);
                }
            }
        });
        delView2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mDel2 != null){
                    mDel2.onHideItemClick(v,position);
                }
            }
        });
        delView3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mDel3 != null){
                    mDel3.onHideItemClick(v,position);
                }
            }
        });
        itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mItemListener != null){
                    mItemListener.onItemClick(position,v);
                }
            }
        });
        convertView = view;
        return convertView;
    }

    public void setOnDel1Listener(OnHideItemClickListener listener){
        mDel1 = listener;
    }

    public void setOnDel2Listener(OnHideItemClickListener listener){
        mDel2 = listener;
    }

    public void setOnDel3Listener(OnHideItemClickListener listener){
        mDel3 = listener;
    }

    public void setOnItemClickListener(OnItemClickListener listener){
        mItemListener = listener;
    }
}
